package com.bham.teamwork.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.bham.teamwork.dao.BaseDao;
import com.bham.teamwork.dao.UserDao;
import com.bham.teamwork.domain.User;
import com.bham.teamwork.domain.UserRowMapper;

/**
 * 
 * @author Federico Bacci
 * @author Alessandro Pozzer
 * @author RuJia Li 
 * 
 */
@Repository(value="userDao")
@SuppressWarnings( { "rawtypes", "unchecked" })
public class UserDaoImpl extends BaseDaoImpl implements UserDao {
	
	@Autowired  
    private BaseDao baseDao;

	@Override
	public void saveUser(User user) {
		if (user.getId()==null||"".equals(user.getId())||"null".equals(user.getId())) {
		   user.setId(getUUID());
		String sql = "insert into t_user(id, username, fullname, password, email) values(?,?,?,?,?)";
		baseDao.updateExecute(sql, user.getId(),user.getUsername(),user.getFullname(),user.getPassword(),user.getEmail());
	    } else {
		String sql = "update t_user set username=?,fullname=?,password=?,email=? where id = ?";
		baseDao.updateExecute(sql, user.getUsername(),user.getFullname(),user.getPassword(),user.getEmail(),user.getId());
	    }
	}


	@Override
	public User getUser(String username) {
		String sql = "SELECT * from t_user where username = ?";
		return (User) baseDao.getObject(sql, new UserRowMapper(), username);
	}

	@Override
	public Map getUserMap(String id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<User> getUser() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void deleteUser(String id) {
		// TODO Auto-generated method stub
		
	}

}
